/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GeradorProvaGUI.java
 *
 * Created on 18/06/2011, 17:34:26
 */
package GUI;

import bo.DisciplinaBO;
import entidades.Disciplina;
import entidades.Questao;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import logic.FuncoesDisciplinaGUI;
import logic.FuncoesQuestoesGUI;
import logic.Mixer;

/**
 *
 * @author Ricardo
 */
public class SistemaMainGUI extends javax.swing.JFrame {

    /** Creates new form GeradorProvaGUI */
    public SistemaMainGUI() {
        initComponents();
        jTextFieldNumDiscFacil.setText("0");
        jTextFieldNumDiscMedia.setText("0");
        jTextFieldNumDiscDificil.setText("0");
        jTextFieldNumMultiFacil.setText("0");
        jTextFieldNumMultiMedia.setText("0");
        jTextFieldNumMultiDificil.setText("0");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanelHome = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jPanelDisciplinas = new javax.swing.JPanel();
        jLabelSelecionaDisciplina = new javax.swing.JLabel();
        jComboBoxListaDeDisciplinas = new javax.swing.JComboBox();
        jButtonCriarDisciplina = new javax.swing.JButton();
        jButtonAlterarDisciplina = new javax.swing.JButton();
        jButtonExcluirDisciplina = new javax.swing.JButton();
        jPanelQuestoes = new javax.swing.JPanel();
        jLabelSelecionaQuestão = new javax.swing.JLabel();
        jComboBoxListaDeQuestoes = new javax.swing.JComboBox();
        jButtonCriarQuestao = new javax.swing.JButton();
        jButtonAlterarQuestao = new javax.swing.JButton();
        jButtonExcluirQuestao = new javax.swing.JButton();
        jPanelGerarProva = new javax.swing.JPanel();
        jLabelDisciplina = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabelSelecionaOpcoesGerarProva1 = new javax.swing.JLabel();
        jComboBoxListaDeDisciplinas1 = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        jListTopicos = new javax.swing.JList();
        jButtonGerarProva = new javax.swing.JButton();
        jButtonLimpar = new javax.swing.JButton();
        jLabelSelecionaOpcoesGerarProva2 = new javax.swing.JLabel();
        jLabelFacil = new javax.swing.JLabel();
        jLabelMedia = new javax.swing.JLabel();
        jLabelDificil = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldNumDiscMedia = new javax.swing.JTextField();
        jTextFieldNumDiscFacil = new javax.swing.JTextField();
        jTextFieldNumDiscDificil = new javax.swing.JTextField();
        jTextFieldNumMultiFacil = new javax.swing.JTextField();
        jTextFieldNumMultiMedia = new javax.swing.JTextField();
        jTextFieldNumMultiDificil = new javax.swing.JTextField();
        jLabelTitulo = new javax.swing.JLabel();
        jLabelSobre = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel2.setText("<html> Olá, seja bem vindo!<br /> <br />  Neste programa você poderá:<br /> <br />   <ul>   <li>Cadastra/alterar/excluir disciplinas</li>   <li>Cadastra/alterar/exclui questões</li>   <li>Gerar prova</li> </ul>  </html>");

        javax.swing.GroupLayout jPanelHomeLayout = new javax.swing.GroupLayout(jPanelHome);
        jPanelHome.setLayout(jPanelHomeLayout);
        jPanelHomeLayout.setHorizontalGroup(
            jPanelHomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelHomeLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(208, Short.MAX_VALUE))
        );
        jPanelHomeLayout.setVerticalGroup(
            jPanelHomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE)
        );

        jLabel2.getAccessibleContext().setAccessibleName("Olá, seja bem vindo!\n\nNeste programa você poderá:\n\n\t- Cadastra/alterar/excluir disciplinas\n\t- Cadastra/alterar/exclui questões\n\t- Gerar prova");

        jTabbedPane1.addTab("Home", jPanelHome);

        jLabelSelecionaDisciplina.setText("Selecione uma disciplina e uma opção:");

        jComboBoxListaDeDisciplinas.setModel(jComboBoxListaDeDisciplinas.getModel());
        jComboBoxListaDeDisciplinas.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
                jComboBoxListaDeDisciplinasPopupMenuWillBecomeVisible(evt);
            }
        });
        jComboBoxListaDeDisciplinas.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                jComboBoxListaDeDisciplinasMouseMoved(evt);
            }
        });
        jComboBoxListaDeDisciplinas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxListaDeDisciplinasActionPerformed(evt);
            }
        });

        jButtonCriarDisciplina.setText("Criar");
        jButtonCriarDisciplina.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCriarDisciplinaActionPerformed(evt);
            }
        });

        jButtonAlterarDisciplina.setText("Alterar");
        jButtonAlterarDisciplina.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAlterarDisciplinaActionPerformed(evt);
            }
        });

        jButtonExcluirDisciplina.setText("Excluir");
        jButtonExcluirDisciplina.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonExcluirDisciplinaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelDisciplinasLayout = new javax.swing.GroupLayout(jPanelDisciplinas);
        jPanelDisciplinas.setLayout(jPanelDisciplinasLayout);
        jPanelDisciplinasLayout.setHorizontalGroup(
            jPanelDisciplinasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDisciplinasLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelDisciplinasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelSelecionaDisciplina)
                    .addGroup(jPanelDisciplinasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jComboBoxListaDeDisciplinas, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanelDisciplinasLayout.createSequentialGroup()
                            .addComponent(jButtonCriarDisciplina)
                            .addGap(18, 18, 18)
                            .addComponent(jButtonAlterarDisciplina)
                            .addGap(18, 18, 18)
                            .addComponent(jButtonExcluirDisciplina))))
                .addContainerGap(204, Short.MAX_VALUE))
        );
        jPanelDisciplinasLayout.setVerticalGroup(
            jPanelDisciplinasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDisciplinasLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelSelecionaDisciplina)
                .addGap(18, 18, 18)
                .addComponent(jComboBoxListaDeDisciplinas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 219, Short.MAX_VALUE)
                .addGroup(jPanelDisciplinasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonCriarDisciplina)
                    .addComponent(jButtonAlterarDisciplina)
                    .addComponent(jButtonExcluirDisciplina))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Disciplinas", jPanelDisciplinas);

        jLabelSelecionaQuestão.setText("Selecione uma questão e uma opção:");

        jComboBoxListaDeQuestoes.setModel(jComboBoxListaDeQuestoes.getModel());
        jComboBoxListaDeQuestoes.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
                jComboBoxListaDeQuestoesPopupMenuWillBecomeVisible(evt);
            }
        });
        jComboBoxListaDeQuestoes.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                jComboBoxListaDeQuestoesMouseMoved(evt);
            }
        });
        jComboBoxListaDeQuestoes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxListaDeQuestoesActionPerformed(evt);
            }
        });

        jButtonCriarQuestao.setText("Criar");
        jButtonCriarQuestao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCriarQuestaoActionPerformed(evt);
            }
        });

        jButtonAlterarQuestao.setText("Alterar");
        jButtonAlterarQuestao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAlterarQuestaoActionPerformed(evt);
            }
        });

        jButtonExcluirQuestao.setText("Excluir");
        jButtonExcluirQuestao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonExcluirQuestaoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelQuestoesLayout = new javax.swing.GroupLayout(jPanelQuestoes);
        jPanelQuestoes.setLayout(jPanelQuestoesLayout);
        jPanelQuestoesLayout.setHorizontalGroup(
            jPanelQuestoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelQuestoesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelQuestoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelQuestoesLayout.createSequentialGroup()
                        .addComponent(jLabelSelecionaQuestão, javax.swing.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE)
                        .addGap(195, 195, 195))
                    .addGroup(jPanelQuestoesLayout.createSequentialGroup()
                        .addGroup(jPanelQuestoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jComboBoxListaDeQuestoes, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanelQuestoesLayout.createSequentialGroup()
                                .addComponent(jButtonCriarQuestao)
                                .addGap(18, 18, 18)
                                .addComponent(jButtonAlterarQuestao)
                                .addGap(18, 18, 18)
                                .addComponent(jButtonExcluirQuestao)))
                        .addContainerGap())))
        );
        jPanelQuestoesLayout.setVerticalGroup(
            jPanelQuestoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelQuestoesLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelSelecionaQuestão)
                .addGap(18, 18, 18)
                .addComponent(jComboBoxListaDeQuestoes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 219, Short.MAX_VALUE)
                .addGroup(jPanelQuestoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonCriarQuestao)
                    .addComponent(jButtonAlterarQuestao)
                    .addComponent(jButtonExcluirQuestao))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Questões", jPanelQuestoes);

        jLabelDisciplina.setText("Disciplina:");

        jLabel3.setText("Tópicos:");

        jLabelSelecionaOpcoesGerarProva1.setText("Selecione a disciplina,tópicos e número de questões para gerar a prova");

        jComboBoxListaDeDisciplinas1.setModel(jComboBoxListaDeDisciplinas1.getModel());
        jComboBoxListaDeDisciplinas1.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
                jComboBoxListaDeDisciplinas1PopupMenuWillBecomeVisible(evt);
            }
        });
        jComboBoxListaDeDisciplinas1.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                jComboBoxListaDeDisciplinas1ComponentShown(evt);
            }
        });
        jComboBoxListaDeDisciplinas1.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                jComboBoxListaDeDisciplinas1MouseMoved(evt);
            }
        });
        jComboBoxListaDeDisciplinas1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxListaDeDisciplinas1ItemStateChanged(evt);
            }
        });
        jComboBoxListaDeDisciplinas1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxListaDeDisciplinas1ActionPerformed(evt);
            }
        });

        jScrollPane1.setViewportView(jListTopicos);

        jButtonGerarProva.setText("Gerar");
        jButtonGerarProva.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGerarProvaActionPerformed(evt);
            }
        });

        jButtonLimpar.setText("Limpar");
        jButtonLimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLimparActionPerformed(evt);
            }
        });

        jLabelSelecionaOpcoesGerarProva2.setText("Número de questões:");

        jLabelFacil.setText("Fácil");

        jLabelMedia.setText("Média");

        jLabelDificil.setText("Difícil");

        jLabel4.setText("Discursivas:");

        jLabel5.setText("Múltipla escolha:");

        jTextFieldNumDiscDificil.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldNumDiscDificilActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelGerarProvaLayout = new javax.swing.GroupLayout(jPanelGerarProva);
        jPanelGerarProva.setLayout(jPanelGerarProvaLayout);
        jPanelGerarProvaLayout.setHorizontalGroup(
            jPanelGerarProvaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelGerarProvaLayout.createSequentialGroup()
                .addGroup(jPanelGerarProvaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanelGerarProvaLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabelSelecionaOpcoesGerarProva1, javax.swing.GroupLayout.DEFAULT_SIZE, 413, Short.MAX_VALUE))
                    .addGroup(jPanelGerarProvaLayout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addGroup(jPanelGerarProvaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelGerarProvaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabelSelecionaOpcoesGerarProva2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(jLabelDisciplina)
                            .addComponent(jLabel3))
                        .addGap(18, 18, 18)
                        .addGroup(jPanelGerarProvaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelGerarProvaLayout.createSequentialGroup()
                                .addGroup(jPanelGerarProvaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jButtonGerarProva, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabelFacil, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jTextFieldNumMultiFacil)
                                    .addComponent(jTextFieldNumDiscFacil, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanelGerarProvaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextFieldNumDiscMedia, javax.swing.GroupLayout.DEFAULT_SIZE, 76, Short.MAX_VALUE)
                                    .addComponent(jLabelMedia, javax.swing.GroupLayout.DEFAULT_SIZE, 76, Short.MAX_VALUE)
                                    .addComponent(jTextFieldNumMultiMedia, javax.swing.GroupLayout.DEFAULT_SIZE, 76, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanelGerarProvaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabelDificil, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE)
                                    .addGroup(jPanelGerarProvaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(jTextFieldNumMultiDificil, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jTextFieldNumDiscDificil, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE)
                                        .addComponent(jButtonLimpar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                            .addGroup(jPanelGerarProvaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jComboBoxListaDeDisciplinas1, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)))))
                .addContainerGap())
        );
        jPanelGerarProvaLayout.setVerticalGroup(
            jPanelGerarProvaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelGerarProvaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelSelecionaOpcoesGerarProva1)
                .addGap(18, 18, 18)
                .addGroup(jPanelGerarProvaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelDisciplina)
                    .addComponent(jComboBoxListaDeDisciplinas1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanelGerarProvaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(33, 33, 33)
                .addGroup(jPanelGerarProvaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelSelecionaOpcoesGerarProva2)
                    .addComponent(jLabelFacil)
                    .addComponent(jLabelMedia)
                    .addComponent(jLabelDificil))
                .addGap(21, 21, 21)
                .addGroup(jPanelGerarProvaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldNumDiscFacil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldNumDiscMedia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldNumDiscDificil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addGroup(jPanelGerarProvaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTextFieldNumMultiFacil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldNumMultiMedia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldNumMultiDificil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanelGerarProvaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonGerarProva)
                    .addComponent(jButtonLimpar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Gerar Prova", jPanelGerarProva);

        jLabelTitulo.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabelTitulo.setText("Gerador de Questões de Prova");

        jLabelSobre.setText("Criado por Diego, Luan, Paula, Ricardo e Taís.");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(101, 101, 101)
                .addComponent(jLabelTitulo))
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 438, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelSobre))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelTitulo)
                .addGap(11, 11, 11)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 344, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabelSobre)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBoxListaDeDisciplinasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxListaDeDisciplinasActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBoxListaDeDisciplinasActionPerformed

    private void jComboBoxListaDeDisciplinas1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxListaDeDisciplinas1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBoxListaDeDisciplinas1ActionPerformed

    private void jComboBoxListaDeQuestoesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxListaDeQuestoesActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBoxListaDeQuestoesActionPerformed

    private void jButtonLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLimparActionPerformed
        jTextFieldNumDiscFacil.setText("0");
        jTextFieldNumDiscMedia.setText("0");
        jTextFieldNumDiscDificil.setText("0");
        jTextFieldNumMultiFacil.setText("0");
        jTextFieldNumMultiMedia.setText("0");
        jTextFieldNumMultiDificil.setText("0");
    }//GEN-LAST:event_jButtonLimparActionPerformed

    private void jButtonCriarDisciplinaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCriarDisciplinaActionPerformed
        ExibirDisciplina();
        DisciplinaEdicaoGUI f = new DisciplinaEdicaoGUI(null,0);
        f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        f.setVisible(true);        
    }//GEN-LAST:event_jButtonCriarDisciplinaActionPerformed

    private void ExibirDisciplina (){
        List<Disciplina> listaDisciplinas = new ArrayList();

        listaDisciplinas = FuncoesDisciplinaGUI.ListarDisciplinas();
        String nomeDisciplina;
        jComboBoxListaDeDisciplinas.removeAllItems();
        for(int i = 0; i < listaDisciplinas.size(); i++){
            nomeDisciplina = listaDisciplinas.get(i).getNomeDisciplina();
            jComboBoxListaDeDisciplinas.addItem(nomeDisciplina);
        }
    }
    
    private void ExibirDisciplina1 (){
        List<Disciplina> listaDisciplinas = new ArrayList();

        listaDisciplinas = FuncoesDisciplinaGUI.ListarDisciplinas();
        String nomeDisciplina;
        jComboBoxListaDeDisciplinas1.removeAllItems();
        for(int i = 0; i < listaDisciplinas.size(); i++){
            nomeDisciplina = listaDisciplinas.get(i).getNomeDisciplina();
            jComboBoxListaDeDisciplinas1.addItem(nomeDisciplina);
        }
        CarregaTopicos();
    }
    
    private void CarregaTopicos(){
        List<Disciplina> listaDisciplinas = new ArrayList();
        List<String> topicos = new ArrayList();
        DefaultListModel listModel = new DefaultListModel();
        String disciplina = (String) jComboBoxListaDeDisciplinas1.getSelectedItem();
        String listaTopicos;
        String nomeDisciplina;
        String topico;
       
        try {
            listaDisciplinas = DisciplinaBO.getInstance().listar();
        } catch(Exception ex) {
            Logger.getLogger(QuestaoEdicaoGUI.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        for(int i = 0; i < listaDisciplinas.size(); i++){
            nomeDisciplina = listaDisciplinas.get(i).getNomeDisciplina();
            if(nomeDisciplina.equalsIgnoreCase(disciplina)){
                listaTopicos = listaDisciplinas.get(i).getTopico();
                topicos = FuncoesQuestoesGUI.listarTopicos(listaTopicos);
                for(int j = 0 ;j < topicos.size();j++){
                    topico = topicos.get(j);
                    listModel.addElement(topico);
                }
                jListTopicos.setModel(listModel);
            }
        }
    }

    private void jButtonAlterarDisciplinaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAlterarDisciplinaActionPerformed
        String nomeDisciplina = (String)jComboBoxListaDeDisciplinas.getSelectedItem();
        FuncoesDisciplinaGUI.FuncionalidadeAlterar(nomeDisciplina);
    }//GEN-LAST:event_jButtonAlterarDisciplinaActionPerformed

    private void jButtonCriarQuestaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCriarQuestaoActionPerformed
        ExibirQuestoes();
        List<Disciplina> listaDisciplinas = new ArrayList();
        listaDisciplinas = FuncoesDisciplinaGUI.ListarDisciplinas();
        if(!listaDisciplinas.isEmpty()){
            QuestaoEdicaoGUI f = new QuestaoEdicaoGUI(null,0,0);
            f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
            f.setVisible(true);
        }
        else 
            ValidarResultado(-1);
    }//GEN-LAST:event_jButtonCriarQuestaoActionPerformed

    private void ExibirQuestoes() {
        List<Disciplina> listaDisciplinas = new ArrayList();
        listaDisciplinas = FuncoesDisciplinaGUI.ListarDisciplinas();
        List<Questao> listaQuestoes = new ArrayList();       
        String enunciadoQuestao;
        jComboBoxListaDeQuestoes.removeAllItems();
        
        for(int i = 0; i < listaDisciplinas.size(); i++){
            try {
                listaQuestoes = listaDisciplinas.get(i).listarQuestao();
            } catch(Exception ex) {
                Logger.getLogger(SistemaMainGUI.class.getName()).log(Level.SEVERE, null, ex);
            }
            for(int j = 0; j < listaQuestoes.size(); j++){
                enunciadoQuestao = listaQuestoes.get(j).getEnunciadoQuestao();
                jComboBoxListaDeQuestoes.addItem(enunciadoQuestao);
            }
        }
    }
    
    private void jButtonAlterarQuestaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAlterarQuestaoActionPerformed
        String enumQuestao = (String) jComboBoxListaDeQuestoes.getSelectedItem();
        FuncoesQuestoesGUI.FuncionalidadeAlterar(enumQuestao);
    }//GEN-LAST:event_jButtonAlterarQuestaoActionPerformed

    private void jButtonExcluirDisciplinaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonExcluirDisciplinaActionPerformed
        String itemSelecionado = null;
        itemSelecionado = (String) jComboBoxListaDeDisciplinas.getSelectedItem();
        Object[] options = { "Sim", "Não" };
        int resposta = JOptionPane.showOptionDialog(null,"Tem certeza que deseja excluir a disciplina?",
        "Confirmação de Exclusão",JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
        options, options[0]);
        if (resposta == JOptionPane.YES_OPTION) {
        int resultado = FuncoesDisciplinaGUI.FuncionalidadeExcluir(itemSelecionado);
        ValidarResultado(resultado);
        }       
    }//GEN-LAST:event_jButtonExcluirDisciplinaActionPerformed

    private void jTextFieldNumDiscDificilActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldNumDiscDificilActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldNumDiscDificilActionPerformed

    private void jButtonExcluirQuestaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonExcluirQuestaoActionPerformed
        String itemSelecionado = null;
        itemSelecionado = (String) jComboBoxListaDeQuestoes.getSelectedItem();
        Object[] options = { "Sim", "Não" };
        int resposta = JOptionPane.showOptionDialog(null,"Tem certeza que deseja excluir essa questão?",
        "Confirmação de Exclusão",JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
        options, options[0]);
        if (resposta == JOptionPane.YES_OPTION) {
        int resultado = FuncoesQuestoesGUI.FuncionalidadeExcluir(itemSelecionado);
        ValidarResultado(resultado);
        ExibirQuestoes();
    }//GEN-LAST:event_jButtonExcluirQuestaoActionPerformed
}

    private void jComboBoxListaDeDisciplinasMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jComboBoxListaDeDisciplinasMouseMoved
        ExibirDisciplina();
    }//GEN-LAST:event_jComboBoxListaDeDisciplinasMouseMoved

    private void jComboBoxListaDeDisciplinasPopupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_jComboBoxListaDeDisciplinasPopupMenuWillBecomeVisible
        ExibirDisciplina();
    }//GEN-LAST:event_jComboBoxListaDeDisciplinasPopupMenuWillBecomeVisible

    private void jComboBoxListaDeQuestoesMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jComboBoxListaDeQuestoesMouseMoved
        ExibirQuestoes();
    }//GEN-LAST:event_jComboBoxListaDeQuestoesMouseMoved

    private void jComboBoxListaDeQuestoesPopupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_jComboBoxListaDeQuestoesPopupMenuWillBecomeVisible
        ExibirQuestoes();
    }//GEN-LAST:event_jComboBoxListaDeQuestoesPopupMenuWillBecomeVisible

    private void jComboBoxListaDeDisciplinas1ComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jComboBoxListaDeDisciplinas1ComponentShown
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBoxListaDeDisciplinas1ComponentShown

    private void jComboBoxListaDeDisciplinas1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxListaDeDisciplinas1ItemStateChanged
        CarregaTopicos();
    }//GEN-LAST:event_jComboBoxListaDeDisciplinas1ItemStateChanged

    private void jComboBoxListaDeDisciplinas1PopupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_jComboBoxListaDeDisciplinas1PopupMenuWillBecomeVisible
        ExibirDisciplina1();
    }//GEN-LAST:event_jComboBoxListaDeDisciplinas1PopupMenuWillBecomeVisible

    private void jComboBoxListaDeDisciplinas1MouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jComboBoxListaDeDisciplinas1MouseMoved
        ExibirDisciplina1();
    }//GEN-LAST:event_jComboBoxListaDeDisciplinas1MouseMoved

    private void jButtonGerarProvaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGerarProvaActionPerformed
        Object[] listaTopicos = jListTopicos.getSelectedValues();
        if(listaTopicos.length == 0 || jComboBoxListaDeDisciplinas1.getSelectedIndex() == -1){
            ValidarResultado(-1);
            jButtonCriarDisciplinaActionPerformed(evt);
        }
           
        String nomeDisciplina = jComboBoxListaDeDisciplinas1.getSelectedItem().toString();
        Disciplina disciplina = FuncoesDisciplinaGUI.RetornaDisciplina(nomeDisciplina);
        String topicos = null;
        
        for(int i=0; i < listaTopicos.length; i++){
            topicos = topicos + ";" + listaTopicos;
        }
        
        
        int qtdeDiscFacil = Integer.parseInt(jTextFieldNumDiscFacil.getText());
        int qtdeDiscMedia = Integer.parseInt(jTextFieldNumDiscMedia.getText());
        int qtdeDiscDificil = Integer.parseInt(jTextFieldNumDiscDificil.getText());
        int qtdeMEFacil = Integer.parseInt(jTextFieldNumMultiFacil.getText());
        int qtdeMEMedia = Integer.parseInt(jTextFieldNumMultiMedia.getText());
        int qtdeMEDificil = Integer.parseInt(jTextFieldNumMultiDificil.getText());
        
        List<Questao> listaQuestoes = new ArrayList<Questao>();
        listaQuestoes = Mixer.sortearQuestoes(disciplina, topicos, qtdeDiscFacil, qtdeDiscMedia, qtdeDiscDificil, 
                qtdeMEFacil, qtdeMEMedia, qtdeMEDificil);
        if(!listaQuestoes.isEmpty()){
            ProvaVisualizacaoGUI f = new ProvaVisualizacaoGUI(listaQuestoes);
            f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
            f.setVisible(true);
        }
        else
            ValidarResultado(-1);
    }//GEN-LAST:event_jButtonGerarProvaActionPerformed

    private void  ValidarResultado(int resultado){
        if(resultado!=-1){
            JOptionPane.showMessageDialog(this,"Operação realizada com sucesso!",this.getTitle() ,JOptionPane.INFORMATION_MESSAGE);
            ExibirDisciplina();
        }
        else
            JOptionPane.showMessageDialog(this,"Erro na realização da operação!",this.getTitle() ,JOptionPane.ERROR_MESSAGE);
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new SistemaMainGUI().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAlterarDisciplina;
    private javax.swing.JButton jButtonAlterarQuestao;
    private javax.swing.JButton jButtonCriarDisciplina;
    private javax.swing.JButton jButtonCriarQuestao;
    private javax.swing.JButton jButtonExcluirDisciplina;
    private javax.swing.JButton jButtonExcluirQuestao;
    private javax.swing.JButton jButtonGerarProva;
    private javax.swing.JButton jButtonLimpar;
    private javax.swing.JComboBox jComboBoxListaDeDisciplinas;
    private javax.swing.JComboBox jComboBoxListaDeDisciplinas1;
    private javax.swing.JComboBox jComboBoxListaDeQuestoes;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabelDificil;
    private javax.swing.JLabel jLabelDisciplina;
    private javax.swing.JLabel jLabelFacil;
    private javax.swing.JLabel jLabelMedia;
    private javax.swing.JLabel jLabelSelecionaDisciplina;
    private javax.swing.JLabel jLabelSelecionaOpcoesGerarProva1;
    private javax.swing.JLabel jLabelSelecionaOpcoesGerarProva2;
    private javax.swing.JLabel jLabelSelecionaQuestão;
    private javax.swing.JLabel jLabelSobre;
    private javax.swing.JLabel jLabelTitulo;
    private javax.swing.JList jListTopicos;
    private javax.swing.JPanel jPanelDisciplinas;
    private javax.swing.JPanel jPanelGerarProva;
    private javax.swing.JPanel jPanelHome;
    private javax.swing.JPanel jPanelQuestoes;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jTextFieldNumDiscDificil;
    private javax.swing.JTextField jTextFieldNumDiscFacil;
    private javax.swing.JTextField jTextFieldNumDiscMedia;
    private javax.swing.JTextField jTextFieldNumMultiDificil;
    private javax.swing.JTextField jTextFieldNumMultiFacil;
    private javax.swing.JTextField jTextFieldNumMultiMedia;
    // End of variables declaration//GEN-END:variables
}
